-- openrtb.lua
wrk.method = "POST"
wrk.path = "/openrtb"
wrk.headers["Content-Type"] = "application/json"

local country_files = {
    IND = "openrtb_request_ind.json",
    MEX = "openrtb_request_mex.json",
    BRA = "openrtb_request_bra.json",
    IDN = "openrtb_request_idn.json"
}

-- 预加载所有国家请求体到内存
local requests = {}
for code, filename in pairs(country_files) do
    local f = io.open(filename, "rb")
    if f then
        requests[code] = f:read("*all")
        f:close()
    end
end

math.randomseed(os.time())

function request()
    -- 随机选择国家代码（转换为大写）
    local codes = {"IND", "MEX", "BRA", "IDN"}
    local selected = codes[math.random(#codes)]

    -- 直接返回预加载的请求体
    return wrk.format(nil, wrk.path, wrk.headers, requests[selected])
end
